//
//  CYYAboutUsViewController.m
//  LetsParty
//
//  Created by YG on 15/9/14.
//  Copyright (c) 2015年 LetsPartyTeam. All rights reserved.
//

#import "CYYAboutUsViewController.h"
#import "CYYHelpViewController.h"

static NSString * const KUITableViewCellIdentifier = @"KUITableViewCellIdentifier";

@interface CYYAboutUsViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * mainTabelView;//主滚动视图
@property (nonatomic, strong) UIView * aboutView;//人员团队底图
@property (nonatomic, strong) UILabel * cLabel;//人员名字
@property (nonatomic, strong) UIButton * okButton;

- (void)initializeUserInterface;

@end

@implementation CYYAboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.baseNavigationBar.backgroundColor = [UIColor whiteColor];
    self.bartitleLabel.text = @"关于我们";
    [self.leftNavButton setImage:[UIImage imageNamed:@"iconfont-zuojiantou"] forState:UIControlStateNormal];
    [self.leftNavButton addTarget:self action:@selector(respondsToLeftButton:) forControlEvents:UIControlEventTouchUpInside];
    [self initializeUserInterface];
    [self.aboutView addSubview:self.cLabel];
    [self.aboutView addSubview:self.okButton];
    [self.okButton addTarget:self action:@selector(respondsToOKButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.aboutView];
    self.aboutView.hidden = YES;
    
}
#pragma mark - system protocol implentations

//行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

//组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
//组头部图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *vView = [[UIView alloc]init];
    vView.frame = DHFlexibleFrame(CGRectMake(0, 0, 200, 300), NO);
    UIImageView * iView = [[UIImageView alloc]init];
    iView.frame = DHFlexibleFrame(CGRectMake(110, 50, 100, 100), NO);
    iView.image = [UIImage imageNamed:@"about"];
    UILabel * versionLabel = [[UILabel alloc]init];
    versionLabel.text = [NSString stringWithFormat:@"Version:%@",[UserModel defaultUser].versionString];
    versionLabel.textAlignment = NSTextAlignmentCenter;
    versionLabel.frame = DHFlexibleFrame(CGRectMake(0, 150, 320, 30), NO);
    [vView addSubview:iView];
    [vView addSubview:versionLabel];
    return vView;
}
//组高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 200 * DHFlexibleVerticalMutiplier();
}
//脚图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *vView = [[UIView alloc]init];
    vView.frame = DHFlexibleFrame(CGRectMake(0, 0, 320, 100), NO);
    UILabel * versionLabel = [[UILabel alloc]init];
    versionLabel.text = @"Copyright (c) 2015年 LetsParty. All rights reserved.";
    versionLabel.textAlignment = NSTextAlignmentCenter;
    versionLabel.numberOfLines = 0;
    versionLabel.frame = DHFlexibleFrame(CGRectMake(0, 50, 320, 60), NO);
    [vView addSubview:versionLabel];
    return vView;
}
//脚图高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 150.f;
}

//cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:KUITableViewCellIdentifier];
    cell.textLabel.text = @[@"帮助",@"反馈",@"关于LetsParty团队"][indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellEditingStyleNone;
    return cell;
}

//selected
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
            [[[ControllerManager sharedManager] rootViewController] pushViewController:[[CYYHelpViewController alloc]init] animated:YES];
              break;
        case 1:
            //反馈直接发送邮件
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"mailto://chaiyangyang@126.com"]];
            break;
        case 2:
            self.aboutView.hidden = NO;
            break;
    }
}

#pragma mark - responds to event
- (void)respondsToOKButton:(UIButton *)button{
    self.aboutView.hidden = YES;
}

#pragma mark - private methods
- (void)initializeUserInterface{
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.mainTabelView];
}

- (void)respondsToLeftButton:(UIButton *)button{
    [[ControllerManager sharedManager].rootViewController popViewControllerAnimated:YES];
}

#pragma mark - getter
- (UITableView *)mainTabelView{
    if (!_mainTabelView) {
        _mainTabelView = ({
            UITableView * tView = [[UITableView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 64, 320, 504), NO) style:UITableViewStyleGrouped];
            tView.delegate = self;
            tView.dataSource = self;
            [tView registerClass:[UITableViewCell class] forCellReuseIdentifier:KUITableViewCellIdentifier];
            tView;
        });
    }
    return _mainTabelView;
}

- (UIView *)aboutView{
    if (!_aboutView) {
        _aboutView = ({
            UIView * cView = [[UIView alloc]initWithFrame:CGRectMake(20, 200, 280, 200) adjustWidth:NO];
            cView.backgroundColor = [UIColor whiteColor];
            cView.layer.cornerRadius = 10;
            cView.layer.masksToBounds = YES;
            cView.layer.borderColor = [UIColor blackColor].CGColor;
            cView.layer.borderWidth = 1.0f;
            cView;
        });
    }
    return _aboutView;
}

- (UILabel *)cLabel{
    if (!_cLabel) {
        _cLabel = ({
            UILabel * cLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, 280, 100) adjustWidth:NO];
            cLabel.text = @"一起嗨(LetsParty)设计团队人员:\n\n柴阳阳、黄帆、梅霖。";
            cLabel.backgroundColor = [UIColor whiteColor];
            cLabel.textAlignment = NSTextAlignmentCenter;
            cLabel.numberOfLines = 0;
            cLabel;
        });
    }
    return _cLabel;
}

- (UIButton *)okButton{
    if (!_okButton) {
        _okButton = ({
            UIButton * cButton = [UIButton buttonWithType:UIButtonTypeCustom];
            cButton.frame = DHFlexibleFrame(CGRectMake(0, 150, 280, 40), NO);
            [cButton setTitle:@"确定" forState:UIControlStateNormal];
            [cButton setTitleColor:COLOR_TagBlue forState:UIControlStateNormal];
            cButton;
        });
    }
    return _okButton;
}

@end
